#!/bin/sh
echo "首先准备数据的配置变量"
db1="ods02"
db2="dw02"
db3="dm02"
t1="ods_cust_info_02"  #客户基本信息表
t2="dw_cust_info_02" #dw层客户基表
t3="dw_product_info_02" #产品码表
t4="dw_addr_info_02" #地址码表 
t5="dm_rk_02" #指标落地表
echo "创建ods层的落地表"
c_t="create table if not exists ${db1}.${t1}(
cust_id string,
cust_name string,
product_code int,
txt_amt int,
addrno int,
age int,
dt string
)
row format delimited fields terminated by '\t';"
#使用hive指令进行创建
echo "$c_t"|hive 
echo $?
echo "ods层客户基表已创建完成"
echo "----------------------分割线----------------------------------"
echo "创建dw层客户基表------------------------------------------------------------"
c_t2="create table if not exists ${db2}.${t2}(
cust_id string,
cust_name string,
product_code int,
txt_amt int,
addrno int,
age int,
dt string,
etl_dt string
)
row format delimited fields terminated by '\t';"
#使用hive -e 指令进行创建
hive -e "$c_t2"
echo $?
echo "dw层客户基表已创建完成"
echo "创建dw层产品码表------------------------------------------------------------"
c_t3="create table if not exists ${db2}.${t3}(
    product_code int,
    product_name string,
    product_type string
)
row format delimited fields terminated by '\t';"
#使用hive -e 指令进行创建
hive -e "$c_t3"
echo $?
echo "dw层产品码表已创建完成"
echo "创建dw层地址码表------------------------------------------------------------"
c_t4="create table if not exists ${db2}.${t4}(
    addrno int,
    addrname string,
    addrcode string
)
row format delimited fields terminated by ',';"
#使用hive -e 指令进行创建
hive -e "$c_t4"
echo $?
echo "dw层地址码表已创建完成"
echo "dw层所有表格已创建完成，进行dm层的表格的创建"
echo "----------------------------------分割线-----------------------------------"
echo "创建dw层地址码表------------------------------------------------------------"
c_t5="create table if not exists ${db3}.${t5}(
     addrname string,
     product_name string,
     s_amt int,
     r_n int,
     etl_dt string
)
row format delimited fields terminated by '\t';"
#使用hive -e 指令进行创建
hive -e "$c_t5"
echo $?
echo 至此数仓的表格已经全部创建完成""


